SET(KMPKG_POLICY_EMPTY_PACKAGE enabled)

if(KMPKG_LIBRARY_LINKAGE STREQUAL "static")
    set(BLA_STATIC ON)
else()
    set(BLA_STATIC OFF)
endif()

# See explanation of which lapack implementation is chosen in portfile.cmake in the blas port

set(BLA_VENDOR Generic)
set(installed_wrapper "${CURRENT_INSTALLED_DIR}/share/lapack/kmpkg-cmake-wrapper.cmake")
set(installed_module "${CURRENT_INSTALLED_DIR}/share/lapack/FindLAPACK.cmake")
if(KMPKG_TARGET_IS_OSX OR KMPKG_TARGET_IS_IOS)
    # Use Apple's accelerate framework where available
    set(BLA_VENDOR Apple)
    configure_file("${CMAKE_CURRENT_LIST_DIR}/kmpkg-cmake-wrapper.cmake.in" "${CURRENT_PACKAGES_DIR}/share/lapack/kmpkg-cmake-wrapper.cmake" @ONLY)
    set(libs "-framework Accelerate")
    set(cflags "-framework Accelerate")
    configure_file("${CMAKE_CURRENT_LIST_DIR}/lapack.pc.in" "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/lapack.pc" @ONLY)
    if(NOT KMPKG_BUILD_TYPE)
        configure_file("${CMAKE_CURRENT_LIST_DIR}/lapack.pc.in" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/lapack.pc" @ONLY)
    endif()
    unset(installed_module)
elseif(KMPKG_TARGET_IS_UWP OR (KMPKG_TARGET_IS_WINDOWS AND KMPKG_TARGET_ARCHITECTURE MATCHES "arm"))
    configure_file("${CURRENT_INSTALLED_DIR}/share/clapack/wrapper/kmpkg-cmake-wrapper.cmake" "${CURRENT_PACKAGES_DIR}/share/lapack/kmpkg-cmake-wrapper.cmake" COPYONLY)
    configure_file("${CURRENT_INSTALLED_DIR}/share/clapack/FindLAPACK.cmake" "${CURRENT_PACKAGES_DIR}/share/lapack/FindLAPACK.cmake" COPYONLY)
    set(libs "-llapack -llibf2c")
    configure_file("${CMAKE_CURRENT_LIST_DIR}/lapack.pc.in" "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/lapack.pc" @ONLY)
    if(NOT KMPKG_BUILD_TYPE)
        set(libs "-llapack -llibf2c")
        configure_file("${CMAKE_CURRENT_LIST_DIR}/lapack.pc.in" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/lapack.pc" @ONLY)
    endif()
else()
    configure_file("${CURRENT_INSTALLED_DIR}/share/lapack-reference/wrapper/kmpkg-cmake-wrapper.cmake" "${CURRENT_PACKAGES_DIR}/share/lapack/kmpkg-cmake-wrapper.cmake" COPYONLY)
    configure_file("${CURRENT_INSTALLED_DIR}/share/lapack-reference/FindLAPACK.cmake" "${CURRENT_PACKAGES_DIR}/share/lapack/FindLAPACK.cmake" COPYONLY)
    set(requires "lapack-reference")
    configure_file("${CMAKE_CURRENT_LIST_DIR}/lapack.pc.in" "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/lapack.pc" @ONLY)
    if(NOT KMPKG_BUILD_TYPE)
        configure_file("${CMAKE_CURRENT_LIST_DIR}/lapack.pc.in" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/lapack.pc" @ONLY)
    endif()
endif()
